package dp.onClass.class3.exer04;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] inputNumArr = new int[n + 1];
        for (int i = 0; i < n + 1; i++) {
            inputNumArr[i] = sc.nextInt();
        }
        int[][] arr = new int[n][2];
        for (int i = 0; i < n; i++) {
            arr[i][0] = inputNumArr[i];
            arr[i][1] = inputNumArr[i + 1];
        }
        // 1. 状态定义：dp[i][j]表示(i, j)区间下标的矩阵连乘最小值
        int[][] dp = new int[n][n];
        // 2. 状态初始化
        // 3. 状态转移
        for (int k = 2; k <= n; k++) { // k个矩阵进行连乘
            for (int i = 0; i < n - k + 1; i++) {
                int j = i + k - 1;
                dp[i][j] = Integer.MAX_VALUE;
                for (int m = i; m < j; m++) {
                    dp[i][j] = Math.min(dp[i][j], dp[i][m] + dp[m + 1][j] + arr[i][0] * arr[m][1] * arr[j][1]);
                }
            }
        }
        // 4. 返回值
        System.out.println(dp[0][n - 1]);
        sc.close();
    }
}
